/**
 * Created by Administrator on 2018/10/8.
 */
// DOM加载完成后执行

$('.website_jianjie').show();
$('#jian_jie').addClass('selectd_style');
$('.website_fencai').hide();
$('.website_zizhi').hide();
$('.website_anli').hide();
$('.lianxi').hide();
$('.wenhua_content').hide();
// 切换tab栏
$('.jian').click(function (event) {
    $('.website_jianjie').show();
    $('.website_fencai').hide();
    $('.website_zizhi').hide();
    $('.website_anli').hide();
    $('.wenhua_content').hide();
    $('.lianxi').hide();
    $('#jian_jie').addClass('selectd_style');
    $('.feng_cai').removeClass('selectd_style');
    $('.zhi_zi').removeClass('selectd_style');
    $('.zhong_xin').removeClass('selectd_style');
    $('.lian_xi').removeClass('selectd_style');
    $('.wen_hua').removeClass('selectd_style');
})
$('.wen').click(function (event) {
    $('.website_jianjie').hide();
    $('.website_fencai').hide();
    $('.website_zizhi').hide();
    $('.website_anli').hide();
    $('.wenhua_content').show();
    $('.lianxi').hide();
    $('#jian_jie').removeClass('selectd_style');
    $('.feng_cai').removeClass('selectd_style');
    $('.zhi_zi').removeClass('selectd_style');
    $('.zhong_xin').removeClass('selectd_style');
    $('.lian_xi').removeClass('selectd_style');
    $('.wen_hua').addClass('selectd_style');
})

$('.feng').click(function (event) {
    $('.website_jianjie').hide();
    $('.website_fencai').show();
    $('.website_zizhi').hide();
    $('.website_anli').hide();
    $('.lianxi').hide();
    $('.wenhua_content').hide();
    $('#jian_jie').removeClass('selectd_style');
    $('.feng_cai').addClass('selectd_style');
    $('.zhi_zi').removeClass('selectd_style');
    $('.zhong_xin').removeClass('selectd_style');
    $('.lian_xi').removeClass('selectd_style');
    $('.wen_hua').removeClass('selectd_style');
})

$('.zhi').click(function (event) {
    $('.website_jianjie').hide();
    $('.website_fencai').hide();
    $('.website_zizhi').show();
    $('.website_anli').hide();
    $('.lianxi').hide();
    $('.wenhua_content').hide();
    $('#jian_jie').removeClass('selectd_style');
    $('.feng_cai').removeClass('selectd_style');
    $('.zhi_zi').addClass('selectd_style');
    $('.zhong_xin').removeClass('selectd_style');
    $('.lian_xi').removeClass('selectd_style');
    $('.wen_hua').removeClass('selectd_style');
})

$('.anli').click(function (event) {
    $('.website_jianjie').hide();
    $('.website_fencai').hide();
    $('.website_zizhi').hide();
    $('.website_anli').show();
    $('.lianxi').hide();
    $('.wenhua_content').hide();
    $('#jian_jie').removeClass('selectd_style');
    $('.feng_cai').removeClass('selectd_style');
    $('.zhi_zi').removeClass('selectd_style');
    $('.zhong_xin').addClass('selectd_style');
    $('.lian_xi').removeClass('selectd_style');
    $('.wen_hua').removeClass('selectd_style');
})

$('.lian').click(function (event) {
    $('.website_jianjie').hide();
    $('.website_fencai').hide();
    $('.website_zizhi').hide();
    $('.website_anli').hide();
    $('.lianxi').show();
    $('.wenhua_content').hide();
    $('#jian_jie').removeClass('selectd_style');
    $('.feng_cai').removeClass('selectd_style');
    $('.zhi_zi').removeClass('selectd_style');
    $('.zhong_xin').removeClass('selectd_style');
    $('.lian_xi').addClass('selectd_style');
    $('.wen_hua').removeClass('selectd_style');
})

//上传的函数
function qiniuUpload(fileData, img, cssClass) {
    var options = {
        url: '/admin/website/qiniu',
        type: 'post',
        data: fileData,
        contentType: false, // 告诉jQuery不要去设置请求头
        processData: false, // 告诉jQuery不要将data属性指定的对象转换为字符串
        success: function (res) {
            if (res.status == 1) {
                 $(img).attr('src', res.data).addClass(cssClass);
            }else {
                alert(res.info);
                return
            }
        }
    }
    $.ajax(options)
}
    // 风采栏上传
    //第一张图
    $('#file_upload1').change(function () {
        oInput = $('#file_upload1')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg1', 'website_fencai_img');

    });
    //第二张图
    $('#file_upload2').change(function () {
        oInput = $('#file_upload2')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg2', 'website_fencai_img');
    });
    //第三张图
    $('#file_upload3').change(function () {
        oInput = $('#file_upload3')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg3', 'website_fencai_img');
    })
    //第四张图
    $('#file_upload4').change(function () {
        oInput = $('#file_upload4')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg4', 'website_fencai_img');
    })
    //第五张图
    $('#file_upload5').change(function () {
        oInput = $('#file_upload5')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg5', 'website_fencai_img');
    })
    //第六张图
    $('#file_upload6').change(function () {
        oInput = $('#file_upload6')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg6', 'website_fencai_img');
    })

    // 企业资质上传
    $('#file_upload_zhao1').change(function () {
        oInput = $('#file_upload_zhao1')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_zhao1');
    })

    // 案例中心上传
    //第一张图
    $('#file_upload_anli1').change(function () {
        oInput = $('#file_upload_anli1')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_anli1', 'website_anli_ul_img');
    })
    //第二张图
    $('#file_upload_anli2').change(function () {
        oInput = $('#file_upload_anli2')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_anli2', 'website_anli_ul_img');
    })
    //第三张图
    $('#file_upload_anli3').change(function () {
        oInput = $('#file_upload_anli3')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_anli3', 'website_anli_ul_img');
    })
    //第四张图
    $('#file_upload_anli4').change(function () {
        oInput = $('#file_upload_anli4')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_anli4', 'website_anli_ul_img');
    })
    //第五张图
    $('#file_upload_anli5').change(function () {
        oInput = $('#file_upload_anli5')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_anli5', 'website_anli_ul_img');
    })
    //第六张图
    $('#file_upload_anli6').change(function () {
        oInput = $('#file_upload_anli6')
        if (oInput.length <= 0) {
            return window.alert('请选择文件')
        }
        var file;
        file = oInput[0].files[0]
        var fd = new FormData()
        fd.append('myfile', file)
        //调用上传函数
        qiniuUpload(fd, '#txtimg_anli6', 'website_anli_ul_img');
    })

//公司风采更新
$('#fencai_submit').click(function (event) {
    var anchor1 = $('input[name=anchor1]').val();
    if(anchor1){
        var fengcai_img1 = $('input[name=anchor1]').val() + '$' + $('#txtimg1').attr('src');
    }else{
        var fengcai_img1 = '';
    }
    var anchor2 = $('input[name=anchor2]').val();
    if(anchor2){
        var fengcai_img2 = $('input[name=anchor2]').val() + '$' + $('#txtimg2').attr('src');
    }else{
        var fengcai_img2 = '';
    }
    var anchor3 = $('input[name=anchor3]').val();
    if(anchor3){
        var fengcai_img3 = $('input[name=anchor3]').val() + '$' + $('#txtimg3').attr('src');
    }else{
        var fengcai_img3 = '';
    }
    var anchor4 = $('input[name=anchor4]').val();
    if(anchor4){
        var fengcai_img4 = $('input[name=anchor4]').val() + '$' + $('#txtimg4').attr('src');
    }else{
        var fengcai_img4 = '';
    }
    var anchor5 = $('input[name=anchor5]').val();
    if(anchor5){
        var fengcai_img5 = $('input[name=anchor5]').val() + '$' + $('#txtimg5').attr('src');
    }else{
        var fengcai_img5 = '';
    }
    var anchor6 = $('input[name=anchor6]').val();
    if(anchor6){
        var fengcai_img6 = $('input[name=anchor6]').val() + '$' + $('#txtimg6').attr('src');
    }else{
        var fengcai_img6 = '';
    }

    $.ajax({
        url: '/admin/website/editFengcai',
        type: 'post',
        data: {fengcai_img1: fengcai_img1, fengcai_img2: fengcai_img2, fengcai_img3: fengcai_img3, fengcai_img4: fengcai_img4, fengcai_img5: fengcai_img5, fengcai_img6: fengcai_img6},
        success: function (res) {
            if(res.status == 1) {
                alert(res.info);
            }else {
                alert('图片的描述不能为空！');
            }
            event.preventDefault();
        }
    })
})
//公司资质更新
$('#zizhi_submit').click(function (event) {
    var register_img = $('#txtimg_zhao1').attr('src');
    var register_name = $('input[name=register_name]').val();
    var register_address = $('input[name=register_address]').val();
    var register_people = $('input[name=register_people]').val();
    var register_money = $('input[name=register_money]').val();
    var rel_register_money = $('input[name=rel_register_money]').val();
    var company_type = $('input[name=company_type]').val();
    var register_scope = $('input[name=register_scope]').val();
    var launch_time = $('input[name=launch_time]').val();
    var register_code = $('input[name=register_code]').val();
    var limit_time = $('input[name=limit_time]').val();
    $.ajax({
        url: '/admin/website/editZizhi',
        data: {
            register_img: register_img,
            register_name: register_name,
            register_address: register_address,
            register_people: register_people,
            register_money: register_money,
            rel_register_money: rel_register_money,
            company_type: company_type,
            register_scope: register_scope,
            launch_time: launch_time,
            register_code: register_code,
            limit_time: limit_time
        },
        type: 'post',
        success: function (res) {
            alert(res.info);
            event.preventDefault();
        }
    })
})

// 案例中心更新
$('#anli_submit').click(function (event) {
    var anli1 =  $('input[name=anchor_anli1]').val();
    if(anli1){
        var anli_img1 = $('input[name=anchor_anli1]').val() + '$' + $('#txtimg_anli1').attr('src');
    }else {
        var anli_img1 = '';
    }
    var anli2 =  $('input[name=anchor_anli2]').val();
    if(anli2){
        var anli_img2 = $('input[name=anchor_anli2]').val() + '$' + $('#txtimg_anli2').attr('src');
    }else {
        var anli_img2 = '';
    }
    var anli3 =  $('input[name=anchor_anli3]').val();
    if(anli3){
        var anli_img3 = $('input[name=anchor_anli3]').val() + '$' + $('#txtimg_anli3').attr('src');
    }else {
        var anli_img3 = '';
    }
    var anli4 =  $('input[name=anchor_anli4]').val();
    if(anli4){
        var anli_img4 = $('input[name=anchor_anli4]').val() + '$' + $('#txtimg_anli4').attr('src');
    }else {
        var anli_img4 = '';
    }
    var anli5 =  $('input[name=anchor_anli5]').val();
    if(anli5){
        var anli_img5 = $('input[name=anchor_anli5]').val() + '$' + $('#txtimg_anli5').attr('src');
    }else {
        var anli_img5 = '';
    }
    var anli6 =  $('input[name=anchor_anli6]').val();
    if(anli6){
        var anli_img6 = $('input[name=anchor_anli6]').val() + '$' + $('#txtimg_anli6').attr('src');
    }else {
        var anli_img6 = '';
    }

    $.ajax({
        url: '/admin/website/editAnli',
        type: 'post',
        data: {anli_img1: anli_img1, anli_img2: anli_img2, anli_img3: anli_img3, anli_img4: anli_img4, anli_img5: anli_img5, anli_img6: anli_img6},
        success: function (res) {
            if(res.status) {
                alert(res.info);
            }else {
                alert('图片描述不能为空！');
            }
            event.preventDefault();
        }
    })
})
//联系我们
$('#lianxi_submit').click(function (event) {
    var company_name = $('input[name=company_name]').val();
    var connect_people = $('input[name=connect_people]').val();
    var connect_method = $('input[name=connect_method]').val();
    var connect_tel = $('input[name=connect_tel]').val();
    var fax_num = $('input[name=fax_num]').val();
    var email = $('input[name=email]').val();
    var company_address = $('input[name=company_address]').val();
    var legalurl = $('input[name=legalurl]').val();
    var preg = /http/;
    var isPreg = preg.test(legalurl);
    if(isPreg){
        alert('更新失败')
        $('.legurl_tips').html('不加http前缀').css({color: 'red'});
        return
    }
    var seo_keywords= $('input[name=seo_keywords]').val();

    $.ajax({
        url: '/admin/website/editLianxi',
        type: 'post',
        data: {
            company_name: company_name,
            connect_people: connect_people,
            connect_method: connect_method,
            connect_tel: connect_tel,
            fax_num: fax_num,
            email: email,
            company_address: company_address,
            legalurl: legalurl,
            seo_keywords: seo_keywords
        },
        success: function (res) {
            alert(res.info);
            event.preventDefault();
        }
    })
})